#!/usr/bin/env python 

import os

for tmpdir in('/Volumes/MAC_SOFT/Applications/tmp',):
	if os.path.isdir(tmpdir):
		print 'is temp dir available'
		break
	else:
		print 'no temp dir available'
		tmpdir=''

	if tmpdir:
		os.chdir(tmpdir)
		cwd=os.getcwd()
		print '*** current tmp dir'
		print cwd

	print '*** create example dir'

	os.mkdir('example')
	os.chdir('example')
	cwd=os.getcwd()
	print '*** new working dir'
	print cwd
	print '*** original dir listing'
	print os.listdir(cwd)

	print 'createing test file...'
	fobj=open('test','w')
	fobj.write('foo\n')
	fobj.write('bar\n')
	fobj.close()
	print '*** updated dir listing'
	print os.listdir(cwd)

	print '*** renaming test to filetest.txt'
	os.rename('test','filetest.txt')
	print '*** updated dir listing'
	print os.listdir(cwd)

	#path=os.path.join(cwd, os.listdir(cwd[0]))
	path=str(cwd)
	print '*** full file pathname'
	print path
	print '*** (pathname,basename)=='
	print os.path.split(path)
	print '*** (filename,ext)=='
	print os.path.splitext(os.path.basename(path))

	print '*** displaying file contents:'
	fobj=open(path+'/filetest.txt')
	for ec in fobj:
		print ec,
	fobj.close()

	print '*** deleting test file'
	os.remove(path)
	print '*** updated dir listing'
	os.chdir(os.pardir)
	print '*** deleting test dir'
	os.rmdir('example')
	print '*** Done'









